先剔除不健康的Replica
依照Replica-priority進行排序
資料同步複製處理之同步差
RunID
在開始測試Redis Server異常自動切換Master前,先確認目前Sentinel叢集狀態.
# 連線到sentinel叢集
# 目前監控的redis server master是mymaster中的 IP: 127.0.0.1 Port: 6380
# Sentinel 26379 狀態
./redis-cli -h 127.0.0.1 -p 26379
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6380,slaves=2,sentinels=3
# Sentinel 26380 狀態
./redis-cli -h 127.0.0.1 -p 26380
127.0.0.1:26380> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6380,slaves=2,sentinels=3
# Sentinel 26381 狀態
./redis-cli -h 127.0.0.1 -p 26381
127.0.0.1:26381> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6380,slaves=2,sentinels=3
# 連線至目前Redis Server (Master) 6380
./redis-cli -h 127.0.0.1 -p 6380
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6381,state=online,offset=3204281,lag=0
slave1:ip=127.0.0.1,port=6379,state=online,offset=3204281,lag=0
master_failover_state:no-failover
master_replid:ea3bc11d99568d87b0496fb83c6f2ccc58425baa
master_replid2:a30878092cdd31e404af76eaa7a2d024c8ae843e
master_repl_offset:3204281
second_repl_offset:19299
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2155706
repl_backlog_histlen:1048576
#
ps -ef|grep redis-server
# kill
kill -9 409413
# 原Redis Server Master 6380 已偵測到異常
+sdown master mymaster 127.0.0.1 6380
# 投票選取Sentinel 此次進行切換的Leader
+vote-for-leader 6337212980ee71b6db0222c50ad525c94c6c48a8 1
# 選取Sentinel 26380為此次進行切換的Leader
+config-update-from sentinel 6337212980ee71b6db0222c50ad525c94c6c48a8 127.0.0.1 26380 @ mymaster 127.0.0.1 6380
# 切換Redis Server Master 6381為新的Master取代原有的
switch-master mymaster 127.0.0.1 6380 127.0.0.1 6381
Connecting to MASTER 127.0.0.1:6381
Full resync from master: c2f5749e8daef12058d98addb48e954afbc92698:1306638
# 確認Redis Server 6380角色為Replica
./redis-cli -h 127.0.0.1 -p 6380
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6381
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:1377655
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:c2f5749e8daef12058d98addb48e954afbc92698
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1377655
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1306639
repl_backlog_histlen:71017
# 確認Sentinel與Redis Server都已恢復
./redis-cli -h 127.0.0.1 -p 26379
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6381,slaves=2,sentinels=3